const router = require('koa-router')();

const { RegisterValidate } = require('../../validators/validator.js')
const User = require('../../models/user.js')

// 注册 新增数据
router.post('/v1/user/register', async (ctx)=> {
  // 接受参数  校验参数
  // email password1 passowrd2 nickname
  const v = await new RegisterValidate().validate(ctx)

  const user = {
    nickname: v.get('body.nickname'),
    email: v.get('body.email'),
    password: v.get('body.password1')
  }

  const r = await User.create(user)

  // 成功返回提示
  throw new global.errs.Success()

  // jwt 令牌可以携带数据
  
})

module.exports = router